//
//  BKHeZhaoStep02ViewController.m
//  baokaodaxue
//
//  Created by dangyangyang on 15/6/4.
//  Copyright (c) 2015年 宏图教育. All rights reserved.
//

#import "BKHeZhaoStep02ViewController.h"
#import "BKHeZhaoTableViewCell.h"
#import "BKChuangJianViewController.h"
#import "BKHeZhaoStep3ViewController.h"
static NSString *rcell = @"Cell";
@interface BKHeZhaoStep02ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation BKHeZhaoStep02ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [_tableView registerClass:[BKHeZhaoTableViewCell class] forCellReuseIdentifier:rcell];
    UIView *backView = [UIView new];
    _tableView.backgroundColor = [UIColor clearColor];
    backView.backgroundColor = [UIColor clearColor];
    _tableView.backgroundView = backView;
    
}
- (void)setDataArray:(NSArray *)dataArray{

    _dataArray = dataArray;
    [_tableView reloadData];
    [_tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionNone];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return [_dataArray count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 44;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

    return 10;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    tableView.layer.cornerRadius = 5;
    return [UIView new];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:rcell];
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    cell.textLabel.text = _dataArray[indexPath.row][@"name"];
    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    UIView *backView = [UIView new];
    backView.backgroundColor = [UIColor clearColor];
    cell.backgroundView = backView;
    cell.selectedBackgroundView = backView;
    
    return cell;
    
}
- (IBAction)p_back:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)p_chuangjian:(id)sender {
    
    BKChuangJianViewController *chuangjian = [[BKChuangJianViewController alloc] initWithNibName:NSStringFromClass([BKChuangJianViewController class]) bundle:nil];
    chuangjian.params = _params;
    
    [self presentViewController:chuangjian animated:YES completion:nil];
    
}
- (IBAction)p_jiaru:(id)sender {
    
    NSIndexPath *indexPath = [_tableView indexPathForSelectedRow];
    
    if (indexPath == nil) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请选择班级" delegate:nil cancelButtonTitle:@"好的" otherButtonTitles:nil, nil];
        [alertView show];
        return;
        
    }
    id  banjiid = _dataArray[indexPath.row][@"id"];
    
    
    BKHeZhaoStep3ViewController *step03 = [[BKHeZhaoStep3ViewController alloc] initWithNibName:NSStringFromClass([BKHeZhaoStep3ViewController class]) bundle:nil];
    [step03.params addEntriesFromDictionary:self.params];
    step03.isTJHiden = YES;
    step03.ban = banjiid;
    [self presentViewController:step03 animated:YES completion:nil];
}

@end
